package gdconf

import (
	"server_cluster/common/logger"
)

// 场景配置表

type SceneConfig struct {
	Id       int32  `csv:"ID" gorm:"primary_key;autoIncrement:false"`
	Type     int32  `csv:"Type,omitempty"`
	SceneTag int32  `csv:"DefaultTime,omitempty"`
	Name     string `csv:"SceneName1,omitempty"`
}

func (s *SceneConfig) TableName() string {
	return "config_scene"
}

func (g *GameDataConfig) saveSceneConfig() {
	saveTableToDb[SceneConfig](g.Db, readTable[SceneConfig](g.CsvPathPrefix+"Scene.csv"))
}

func (g *GameDataConfig) loadSceneConfig() {
	g.GameDataMaps.SceneConfigMap = make(map[int32]*SceneConfig)
	for _, sceneConfig := range loadTableFromDb[SceneConfig](g.Db) {
		g.GameDataMaps.SceneConfigMap[sceneConfig.Id] = sceneConfig
	}
	logger.Info("SceneConfig Count: %v", len(g.GameDataMaps.SceneConfigMap))
}

func GetSceneConfig(sceneId int32) *SceneConfig {
	value, exist := CONF.GameDataMaps.SceneConfigMap[sceneId]
	if !exist {
		logger.Error("[ConfigNotFound] SceneConfig, sceneId: %v", sceneId)
		return nil
	}
	return value
}

func GetSceneConfigMap() map[int32]*SceneConfig {
	return CONF.GameDataMaps.SceneConfigMap
}
